﻿using Common.Communal;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Api.Write.Applications.Commands.Roles;

namespace System.Api.Write.Controllers
{
    /// <summary>
    /// 角色
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        public RoleController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 新增角色
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public Task<ApiResult<int>> AddRole(RoleCreateCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 更新角色
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public Task<ApiResult<int>> UpdateRole(RoleUpdateCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public Task<ApiResult<int>> DeleteRole([FromQuery]RoleDeleteCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 启用/禁用角色
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public Task<ApiResult<int>> EnableRole([FromQuery]RoleEnableCommand command)
        {
            return mediator.Send(command);
        }
    }
}
